#ifndef _SOCKET_H_
#define _SOCKET_H_

#include <libuv/uv.h>
#include <string>
#include <sstream>
#include <memory>
#include <uvw/uvw.hpp>
#include <functional>
#include <google/protobuf/message.h>
#include "session.h"
#include "../myrpc/myrpc.pb.h"


namespace myrpc {
namespace mynet {

class TcpListener : public std::enable_shared_from_this<TcpListener>
{

public:
  TcpListener() = default;
  ~TcpListener() = default;


  int Init();
  int Listen(std::string  ip, int port);
  int Close();
  void SetConnectReach(std::function<void(std::shared_ptr<myrpc::mynet::Session>)> f);

private:
	
  std::function<void(std::shared_ptr<myrpc::mynet::Session>)> _ConnectReach;
  std::string ip_;
  unsigned short int port_;
  std::shared_ptr<uvw::TcpHandle>  tcphandler_;
  std::shared_ptr<uvw::Loop> loop_;

};

typedef std::shared_ptr<TcpListener>  TcpHandlePtr;

} // namespace mynet
} // namespace myrpc

#endif